{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyblp\n",
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "n=8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "if n % 4==0:\n",
    "    print(True)\n",
    "else: \n",
    "    print(False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C:\\Users\\User\\Dropbox\\WB Project\\Estimation\n"
     ]
    }
   ],
   "source": [
    "%cd \"C:\\Users\\User\\Dropbox\\WB Project\\Estimation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "product_data = pd.read_csv('product_data.csv',dtype=np.float64)\n",
    "agent_data = pd.read_csv('agent_data.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1 + hpwt + mpg + transmission + electric + ele_X_CE + drv_rng,\n",
       " prices + mpg,\n",
       " hpwt + mpg + transmission + bat_size + Absorb[C(ym_ids)])"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "product_formulations = (\n",
    "   pyblp.Formulation('1 + hpwt + mpg + transmission + electric+ ele_X_CE+drv_rng'),\n",
    "   pyblp.Formulation('0+prices + mpg'),\n",
    "   pyblp.Formulation('1 + hpwt + mpg + transmission+bat_size',absorb='C(ym_ids)')\n",
    ")\n",
    "product_formulations\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Initializing the problem ...\n",
      "Absorbing supply-side fixed effects ...\n",
      "Initialized the problem after 00:00:00.\n",
      "\n",
      "Dimensions:\n",
      "=========================================================\n",
      " T    N     F     I     K1    K2    K3    MD    MS    ES \n",
      "---  ----  ---  -----  ----  ----  ----  ----  ----  ----\n",
      "72   9999  61   72000   7     2     4     35    32    1  \n",
      "=========================================================\n",
      "\n",
      "Formulations:\n",
      "====================================================================================================\n",
      "       Column Indices:           0      1         2             3           4         5         6   \n",
      "-----------------------------  ------  ----  ------------  ------------  --------  --------  -------\n",
      " X1: Linear Characteristics      1     hpwt      mpg       transmission  electric  ele_X_CE  drv_rng\n",
      "X2: Nonlinear Characteristics  prices  mpg                                                          \n",
      "X3: Log Cost Characteristics    hpwt   mpg   transmission    bat_size                               \n",
      "====================================================================================================\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Dimensions:\n",
       "=========================================================\n",
       " T    N     F     I     K1    K2    K3    MD    MS    ES \n",
       "---  ----  ---  -----  ----  ----  ----  ----  ----  ----\n",
       "72   9999  61   72000   7     2     4     35    32    1  \n",
       "=========================================================\n",
       "\n",
       "Formulations:\n",
       "====================================================================================================\n",
       "       Column Indices:           0      1         2             3           4         5         6   \n",
       "-----------------------------  ------  ----  ------------  ------------  --------  --------  -------\n",
       " X1: Linear Characteristics      1     hpwt      mpg       transmission  electric  ele_X_CE  drv_rng\n",
       "X2: Nonlinear Characteristics  prices  mpg                                                          \n",
       "X3: Log Cost Characteristics    hpwt   mpg   transmission    bat_size                               \n",
       "===================================================================================================="
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "problem = pyblp.Problem(product_formulations, product_data,None, agent_data, costs_type='log')\n",
    "problem"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [],
   "source": [
    "initial_sigma = np.diag([0.06265337, 0.000000001 ])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Solving the problem ...\n",
      "\n",
      "Nonlinear Coefficient Initial Values:\n",
      "====================================\n",
      "Sigma:     prices           mpg     \n",
      "------  -------------  -------------\n",
      "prices  +6.265337E-02               \n",
      " mpg    +0.000000E+00  +1.000000E-09\n",
      "====================================\n",
      "\n",
      "Nonlinear Coefficient Lower Bounds:\n",
      "====================================\n",
      "Sigma:     prices           mpg     \n",
      "------  -------------  -------------\n",
      "prices  +0.000000E+00               \n",
      " mpg    +0.000000E+00  +0.000000E+00\n",
      "====================================\n",
      "\n",
      "Nonlinear Coefficient Upper Bounds:\n",
      "====================================\n",
      "Sigma:     prices           mpg     \n",
      "------  -------------  -------------\n",
      "prices      +INF                    \n",
      " mpg    +0.000000E+00      +INF     \n",
      "====================================\n",
      "\n",
      "Updating starting values for the weighting matrix and delta ...\n",
      "Computed results after 00:00:48.\n",
      "\n",
      "Starting optimization ...\n",
      "\n",
      "GMM   Optimization   Objective   Fixed Point  Contraction  Clipped  Clipped    Objective      Objective      Projected                                \n",
      "Step   Iterations   Evaluations  Iterations   Evaluations  Shares    Costs       Value       Improvement   Gradient Norm             Theta            \n",
      "----  ------------  -----------  -----------  -----------  -------  -------  -------------  -------------  -------------  ----------------------------\n",
      " 1         0             1            0           73          0       114    +2.519441E+02                 +4.020092E+03  +6.265337E-02, +1.000000E-09\n",
      "\n",
      "At least one error was encountered. As long as the optimization routine does not get stuck at values of theta that give rise to errors, this is not necessarily a problem. If the errors persist or seem to be impacting the optimization results, consider setting an error punishment or following any of the other suggestions below:\n",
      "The fixed point computation of delta failed to converge. This problem can sometimes be mitigated by increasing the maximum number of fixed point iterations, increasing the fixed point tolerance, choosing more reasonable initial parameter values, setting more conservative parameter or share bounds, or using different iteration or optimization configurations.\n",
      "\n",
      " 1         0             2          95805       287550        0       34     +1.059077E+05                 +2.109466E+05  +1.062653E+00, +9.997512E-10\n",
      " 1         0             3           621         1943         0       83     +3.894378E+02                 +5.162332E+03  +8.029388E-02, +9.999956E-10\n",
      " 1         0             4           540         1687         0       116    +2.575304E+02                 +3.840473E+03  +6.410175E-02, +9.999996E-10\n",
      " 1         0             5           511         1606         0       115    +2.525442E+02                 +3.339719E+03  +6.286014E-02, +9.999999E-10\n",
      " 1         0             6           488         1548         0       115    +2.519798E+02                 +3.249284E+03  +6.268876E-02, +1.000000E-09\n",
      " 1         0             7           467         1491         0       115    +2.519003E+02  +4.375797E-02  +3.236890E+03  +6.266427E-02, +1.000000E-09\n",
      " 1         1             8           449         1434         0       115    +2.518846E+02  +1.572876E-02  +3.234442E+03  +6.265941E-02, +0.000000E+00\n",
      " 1         2             9           562         1748         0       118    +2.540817E+02                 +2.260141E+04  +5.623595E-02, +0.000000E+00\n",
      " 1         2            10           558         1738         0       108    +2.567558E+02                 +3.741418E+02  +5.918193E-02, +0.000000E+00\n",
      " 1         2            11           524         1658         0       109    +2.569210E+02                 +2.641717E+02  +6.206044E-02, +0.000000E+00\n",
      " 1         2            12           484         1531         0       114    +2.519430E+02                 +1.444644E+03  +6.262747E-02, +0.000000E+00\n",
      " 1         2            13           432         1368         0       114    +2.519359E+02                 +6.314150E+03  +6.265498E-02, +0.000000E+00\n",
      " 1         2            14           453         1439         0       115    +2.518839E+02  +6.910080E-04  +3.234335E+03  +6.265919E-02, +0.000000E+00\n",
      " 1         2            15           442         1405         0       114    +2.519244E+02                 +1.039772E+04  +6.265641E-02, +0.000000E+00\n",
      " 1         2            16           453         1436         0       115    +2.518835E+02  +3.793129E-04  +3.234276E+03  +6.265908E-02, +0.000000E+00\n",
      " 1         2            17           441         1407         0       114    +2.519127E+02                 +1.598743E+04  +6.265732E-02, +0.000000E+00\n",
      " 1         2            18           449         1435         0       115    +2.518833E+02  +2.352945E-04  +3.234239E+03  +6.265900E-02, +0.000000E+00\n",
      " 1         2            19           444         1420         0       114    +2.519017E+02                 +2.342691E+04  +6.265789E-02, +0.000000E+00\n",
      " 1         2            20           452         1430         0       115    +2.518831E+02  +1.832929E-04  +3.234211E+03  +6.265895E-02, +0.000000E+00\n",
      " 1         2            21           449         1429         0       114    +2.518918E+02                 +3.282157E+04  +6.265825E-02, +0.000000E+00\n",
      " 1         2            22           450         1429         0       115    +2.518828E+02  +2.673627E-04  +3.234169E+03  +6.265886E-02, +0.000000E+00\n",
      " 1         2            23           449         1426         0       114    +2.518840E+02                 +4.293717E+04  +6.265846E-02, +0.000000E+00\n",
      " 1         2            24           447         1426         0       115    +2.518823E+02  +5.675036E-04  +3.234081E+03  +6.265869E-02, +0.000000E+00\n",
      " 1         2            25           448         1428         0       115    +2.518818E+02  +4.901236E-04  +3.234004E+03  +6.265854E-02, +0.000000E+00\n",
      " 1         3            26           563         1747         0       118    +2.542011E+02                 +1.804837E+04  +5.623001E-02, +0.000000E+00\n",
      " 1         3            27           556         1739         0       108    +2.567683E+02                 +2.842740E+02  +5.921989E-02, +0.000000E+00\n",
      " 1         3            28           524         1657         0       109    +2.569221E+02                 +2.395863E+02  +6.206504E-02, +0.000000E+00\n",
      " 1         3            29           487         1538         0       114    +2.519425E+02                 +1.459501E+03  +6.262714E-02, +0.000000E+00\n",
      " 1         3            30           425         1344         0       114    +2.519398E+02                 +5.180471E+03  +6.265431E-02, +0.000000E+00\n",
      " 1         3            31           447         1419         0       114    +2.518876E+02                 +3.791942E+04  +6.265837E-02, +0.000000E+00\n",
      " 1         3            32           448         1430         0       115    +2.518818E+02  +1.222831E-05  +3.234003E+03  +6.265853E-02, +0.000000E+00\n",
      " 1         3            33           448         1429         0       114    +2.518854E+02                 +4.089273E+04  +6.265842E-02, +0.000000E+00\n",
      " 1         3            34           447         1420         0       115    +2.518818E+02  +8.623634E-06  +3.234001E+03  +6.265853E-02, +0.000000E+00\n",
      " 1         3            35           448         1429         0       114    +2.518839E+02                 +4.307853E+04  +6.265846E-02, +0.000000E+00\n",
      " 1         3            36           450         1429         0       115    +2.518818E+02  +6.631912E-06  +3.234000E+03  +6.265853E-02, +0.000000E+00\n",
      " 1         3            37           449         1431         0       114    +2.518829E+02                 +4.461203E+04  +6.265848E-02, +0.000000E+00\n",
      " 1         3            38           446         1425         0       115    +2.518818E+02  +6.110120E-06  +3.233999E+03  +6.265853E-02, +0.000000E+00\n",
      " 1         3            39           449         1435         0       114    +2.518822E+02                 +4.564174E+04  +6.265850E-02, +0.000000E+00\n",
      " 1         3            40           450         1433         0       115    +2.518817E+02  +8.593239E-06  +3.233998E+03  +6.265852E-02, +0.000000E+00\n",
      " 1         3            41           450         1429         0       114    +2.518818E+02                 +4.628130E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         3            42           450         1428         0       115    +2.518817E+02  +1.909964E-05  +3.233995E+03  +6.265852E-02, +0.000000E+00\n",
      " 1         3            43           444         1419         0       115    +2.518817E+02  +2.323896E-05  +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         3            44           446         1423         0       114    +2.518818E+02                 +4.637593E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         3            45           444         1419         0       115    +2.518817E+02                 +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         4            46           563         1751         0       118    +2.542176E+02                 +1.753580E+04  +5.622909E-02, +0.000000E+00\n",
      " 1         4            47           555         1740         0       108    +2.567698E+02                 +2.711456E+02  +5.922547E-02, +0.000000E+00\n",
      " 1         4            48           527         1661         0       109    +2.569223E+02                 +2.356410E+02  +6.206577E-02, +0.000000E+00\n",
      " 1         4            49           484         1532         0       114    +2.519426E+02                 +1.457555E+03  +6.262718E-02, +0.000000E+00\n",
      " 1         4            50           427         1349         0       114    +2.519398E+02                 +5.169512E+03  +6.265430E-02, +0.000000E+00\n",
      " 1         4            51           448         1428         0       114    +2.518885E+02                 +3.675656E+04  +6.265835E-02, +0.000000E+00\n",
      " 1         4            52           448         1423         0       114    +2.518818E+02                 +4.634039E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         4            53           453         1432         0       115    +2.518817E+02  +2.152328E-07  +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         4            54           450         1430         0       114    +2.518818E+02                 +4.641337E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         4            55           446         1421         0       115    +2.518817E+02  +1.612219E-07  +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         4            56           449         1428         0       114    +2.518817E+02                 +4.649327E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         4            57           448         1427         0       115    +2.518817E+02  +1.981755E-07  +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         4            58           449         1424         0       114    +2.518817E+02                 +4.651161E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         4            59           449         1428         0       115    +2.518817E+02  +4.601868E-07  +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         4            60           453         1434         0       115    +2.518817E+02  +6.995597E-07  +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         4            61           446         1423         0       114    +2.518817E+02                 +4.651449E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         4            62           452         1433         0       115    +2.518817E+02  +4.136126E-09  +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         4            63           447         1423         0       114    +2.518817E+02                 +4.651936E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         4            64           452         1433         0       115    +2.518817E+02                 +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         5            65           562         1748         0       118    +2.542175E+02                 +1.753784E+04  +5.622909E-02, +0.000000E+00\n",
      " 1         5            66           556         1733         0       108    +2.567698E+02                 +2.711996E+02  +5.922545E-02, +0.000000E+00\n",
      " 1         5            67           525         1660         0       109    +2.569223E+02                 +2.356591E+02  +6.206577E-02, +0.000000E+00\n",
      " 1         5            68           489         1539         0       114    +2.519426E+02                 +1.457590E+03  +6.262718E-02, +0.000000E+00\n",
      " 1         5            69           425         1344         0       114    +2.519399E+02                 +5.168704E+03  +6.265430E-02, +0.000000E+00\n",
      " 1         5            70           449         1424         0       114    +2.518885E+02                 +3.673232E+04  +6.265834E-02, +0.000000E+00\n",
      " 1         5            71           449         1433         0       114    +2.518818E+02                 +4.630099E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         5            72           452         1431         0       114    +2.518817E+02                 +4.651634E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         5            73           448         1425         0       115    +2.518817E+02  +2.676074E-09  +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         5            74           449         1428         0       114    +2.518817E+02                 +4.651971E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         5            75           450         1431         0       115    +2.518817E+02  +1.483329E-10  +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         5            76           448         1426         0       114    +2.518817E+02                 +4.651977E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         5            77           449         1429         0       115    +2.518817E+02  +6.451728E-11  +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         5            78           449         1429         0       114    +2.518817E+02                 +4.651982E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         5            79           450         1430         0       115    +2.518817E+02  +1.984404E-10  +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         5            80           453         1432         0       115    +2.518817E+02  +2.501110E-12  +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         5            81           448         1429         0       114    +2.518817E+02                 +4.651986E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         5            82           450         1432         0       115    +2.518817E+02  +5.744027E-11  +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         5            83           448         1425         0       114    +2.518817E+02                 +4.651987E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         5            84           449         1430         0       115    +2.518817E+02  +1.067235E-10  +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         5            85           267          857         0        0     +1.007576E+03                 +0.000000E+00  +0.000000E+00, +0.000000E+00\n",
      " 1         5            86           555         1724         0       109    +2.546167E+02                 +1.209710E+03  +6.018929E-02, +0.000000E+00\n",
      " 1         5            87           519         1639         0       109    +2.568578E+02                 +1.332361E+03  +6.222712E-02, +0.000000E+00\n",
      " 1         5            88           471         1496         0       114    +2.519565E+02                 +5.262896E+02  +6.264023E-02, +0.000000E+00\n",
      " 1         5            89           442         1403         0       114    +2.519196E+02                 +1.247672E+04  +6.265683E-02, +0.000000E+00\n",
      " 1         5            90           450         1433         0       114    +2.518837E+02                 +4.335397E+04  +6.265846E-02, +0.000000E+00\n",
      " 1         5            91           446         1425         0       114    +2.518817E+02                 +4.646294E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         5            92           447         1427         0       114    +2.518817E+02                 +4.651903E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         5            93           451         1436         0       115    +2.518817E+02                 +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         5            94           446         1424         0       115    +2.518817E+02                 +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         5            95           448         1430         0       114    +2.518817E+02                 +4.651947E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         5            96           450         1429         0       115    +2.518817E+02                 +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         5            97           449         1428         0       114    +2.518817E+02                 +4.651962E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         5            98           448         1425         0       115    +2.518817E+02                 +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         5            99           451         1429         0       115    +2.518817E+02                 +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         5            100          448         1429         0       114    +2.518817E+02                 +4.651976E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         5            101          451         1432         0       115    +2.518817E+02                 +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         5            102          447         1426         0       114    +2.518817E+02                 +4.651981E+04  +6.265851E-02, +0.000000E+00\n",
      " 1         5            103          448         1429         0       115    +2.518817E+02                 +3.233991E+03  +6.265851E-02, +0.000000E+00\n",
      " 1         5            104          446         1424         0       114    +2.518817E+02                 +4.651984E+04  +6.265851E-02, +0.000000E+00\n",
      "\n",
      "The optimization routine failed to converge. This problem can sometimes be mitigated by choosing more reasonable initial parameter values, setting more conservative bounds, or configuring other optimization settings.\n",
      "\n",
      "\n",
      "Optimization failed after 02:21:39.\n",
      "Computing the Hessian and estimating standard errors ...\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "nan_to_num() got an unexpected keyword argument 'nan'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-66-553554b288a9>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      5\u001b[0m     \u001b[0mse_type\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'clustered'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      6\u001b[0m     \u001b[0minitial_update\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m     \u001b[0mmethod\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'1s'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      8\u001b[0m )\n\u001b[0;32m      9\u001b[0m \u001b[0mresults\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\pyblp\\economies\\problem.py\u001b[0m in \u001b[0;36msolve\u001b[1;34m(self, sigma, pi, rho, beta, gamma, sigma_bounds, pi_bounds, rho_bounds, beta_bounds, gamma_bounds, delta, method, initial_update, optimization, scale_objective, check_optimality, finite_differences, error_behavior, error_punishment, delta_behavior, iteration, fp_type, shares_bounds, costs_bounds, W, center_moments, W_type, se_type, micro_moments, extra_micro_covariances)\u001b[0m\n\u001b[0;32m    670\u001b[0m                 \u001b[0mfinal_progress\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlast_results\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstep\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlast_step\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstep_start_time\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0moptimization_start_time\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    671\u001b[0m                 \u001b[0moptimization_end_time\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0moptimization_stats\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0miteration_stats\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mscale_objective\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0miteration\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfp_type\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 672\u001b[1;33m                 \u001b[0mshares_bounds\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcosts_bounds\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mextra_micro_covariances\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcenter_moments\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mW_type\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mse_type\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    673\u001b[0m             )\n\u001b[0;32m    674\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_handle_errors\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresults\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_errors\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0merror_behavior\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\pyblp\\results\\problem_results.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, progress, last_results, step, last_step, step_start_time, optimization_start_time, optimization_end_time, optimization_stats, iteration_stats, scaled_objective, iteration, fp_type, shares_bounds, costs_bounds, extra_micro_covariances, center_moments, W_type, se_type)\u001b[0m\n\u001b[0;32m    430\u001b[0m                 \u001b[1;31m# use the delta method to compute covariances for the parameters in sigma squared\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    431\u001b[0m                 \u001b[0mtheta_covariances\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mparameter_covariances\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parameters\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mP\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m:\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parameters\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mP\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 432\u001b[1;33m                 \u001b[0msigma_vector_covariances\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parameters\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mextract_sigma_vector_covariances\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtheta_covariances\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    433\u001b[0m                 sigma_squared_vector_covariances = compute_sigma_squared_vector_covariances(\n\u001b[0;32m    434\u001b[0m                     \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msigma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msigma_vector_covariances\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\pyblp\\parameters.py\u001b[0m in \u001b[0;36mextract_sigma_vector_covariances\u001b[1;34m(self, theta_covariances)\u001b[0m\n\u001b[0;32m    562\u001b[0m         \u001b[1;31m# extract corresponding rows and columns from the theta covariances, taking zeros for fixed elements\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    563\u001b[0m         \u001b[0mpadded_covariances\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpad\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtheta_covariances\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mpad_width\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'constant'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mconstant_values\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 564\u001b[1;33m         \u001b[0mindices\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnan_to_num\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msigma_vector_indices\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnan\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mP\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    565\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0mpadded_covariances\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mindices\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mindices\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: nan_to_num() got an unexpected keyword argument 'nan'"
     ]
    }
   ],
   "source": [
    "\n",
    "results = problem.solve(\n",
    "    initial_sigma,\n",
    "    costs_bounds=(0.001, None),\n",
    "    W_type='clustered',\n",
    "    se_type='clustered',\n",
    "    initial_update=True,\n",
    "    method='1s',\n",
    ")\n",
    "results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
